package com.game.animation;

import com.game.basic.BasicRegion;
import com.game.config.Config;
import com.game.utils.AnimationInterpolatorUtil;

/**
* @author oven:
* @version 创建时间：2012-11-12 下午3:32:04
* 抛物运动
*/
public class AnimationParabolic extends Animation{
	float transy_up;//上升的距离
	float transy_down;//下降的距离
	float transx;
	float upTime;//上升的时间
	float downTime;//下降的时间
	
	
	public AnimationParabolic(AnimationFix animationfix,
							  AnimationCallBack animationCallBack, 
							  float delayTime, 
							  boolean keep,
							  float transy_up,
							  float transy_down,
							  float transx,
							  float upTime,
							  float downTime) {
		super(animationfix, animationCallBack, delayTime, keep,upTime+downTime);
		this.transy_up=transy_up;
		this.transy_down=transy_down;
		this.upTime=upTime*Config.FPS/1000f;
		this.downTime=downTime*Config.FPS/1000f;
		this.transx=transx;
		this.animationType=ANIMATION_TYPE_TRANSLATE;
	}

	@Override
	protected void step() {
		if(time_step<=upTime){
			float input = time_step/upTime;
			float perc= AnimationInterpolatorUtil.getDecelerate(input);
			animationfix.setTransy(0-perc*transy_up);
		}else{
			if(time_step<=(upTime+downTime)){
				float input = (time_step-upTime)/downTime;
				float perc= AnimationInterpolatorUtil.getAccelerate(input);
				animationfix.setTransy(perc*transy_down-transy_up);
			}
		}
		animationfix.setTransx(time_step/(upTime+downTime)*transx);
	}

	@Override
	protected void keepState() {
		BasicRegion r=animationfix.getReferenceRegion();
		r.setPostx(r.getPostx()+transx);
		r.setPosty(r.getPosty()+(transy_down-transy_up));
	}
}

